package cn.leedsoft.luma.plugins.quartz;

import org.quartz.spi.TriggerFiredBundle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.scheduling.quartz.AdaptableJobFactory;

/**
 * Created by leeds on 2016/6/1 19:37.
 * 作用：是将传给Scheduler的job class自动装配（autowire）。（即可以使用@Autowired或者@Resource，对job class的属性，进行注入）
 */
public class AutowireJobFactory extends AdaptableJobFactory{
    @Autowired
    private AutowireCapableBeanFactory autowireCapableBeanFactory;

    @Override
    protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
        Object job = super.createJobInstance(bundle);
        autowireCapableBeanFactory.autowireBean(job);
        return job;
    }
}
